package mymyoux.utils
{
	import flash.external.ExternalInterface;
	import flash.system.Capabilities;
	/**
	 * Retrieve some informations about Movie and System.
	 */
	public class Infos
	{
	/**
	 * @private
	 */
		public function Infos()
		{
		}
		/**
		 * Return current url without hash.
		 * @see #urlAbsolute()
		 */
		public static function get url():String
		{
			if(javascriptEnabled)
			{
				var url:String= urlAbsolute;
				if(url.length>0)
				{
					var hash:String=Infos.hash;
					if(hash.length>0)
					{
						return url.substring(0,url.length-hash.length-1);
					}
					return url;
				}
			}
			return "";
		}
		/**
		 * return current complete url.
		 */
		public static function get urlAbsolute():String
		{
			if(javascriptEnabled)
			{
				return ExternalInterface.call("eval","function private_url_javascript_embeded(){return window.document.location.href;} private_url_javascript_embeded();");
			}
			return "";
		}
		/**
		 * return current hash without #
		 */
		public static function get hash():String
		{
			if(javascriptEnabled)
			{
				var hash:String=ExternalInterface.call("eval","function private_hash_javascript_embeded(){return window.document.location.hash;} private_hash_javascript_embeded();");
				if(hash.length>0)
				{
					return hash.substring(1);
				}
			}
			return "";
		}
		/**
		 * Indicate if javasript is enabled or not.
		 */
		public static function get javascriptEnabled():Boolean
		{
			return ExternalInterface.available;
		}
		/**
		 * return current navigagor.
		 */
		public static function get navigator():String
		{
			if(javascriptEnabled)
			{
				return ExternalInterface.call("eval","function private_navigator_javascript_embeded(){return navigator.appName;} private_navigator_javascript_embeded();");
			}
			return "";
		}
		/**
		 * return current navigator version.
		 */
		public static function get navigatorVersion():String
		{
			if(javascriptEnabled)
			{
				var version:String=ExternalInterface.call("eval","function private_navigator_version_javascript_embeded(){return navigator.appVersion;} private_navigator_version_javascript_embeded();");
				//return version.indexOf(" ")>-1?version.substring(0,version.indexOf(" ")+1):version;
				if(version.indexOf("MSIE ")>-1)
				{
					return version.substring(version.indexOf("MSIE ")+5,version.indexOf(";",version.indexOf("MSIE ")+5));
				}
				return version.indexOf(" ")>-1?version.substring(0,version.indexOf(" ")+1):version;
			}
			return "";
		}
		/**
		 * return os.
		 */
		public static function get os():String
		{
			return Capabilities.os;
		}
		/**
		 * return player version.
		 */
		public static function get version():String
		{
			return Capabilities.version.substring(Capabilities.version.indexOf(" ")+1);
		}
	}
}